<?php

//error reporting
ini_set('display_errors', '1');
?>

<?php


// Define path to application directory
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// create line of the pathes
$pathes = implode(PATH_SEPARATOR, array (
	realpath(APPLICATION_PATH . '/../library'),
	realpath(APPLICATION_PATH . '/models'),
	
));

set_include_path($pathes);

require_once ('Zend/Loader/Autoloader.php');
require_once ('Smarty/Smarty.class.php');

$autoloader = Zend_Loader_Autoloader :: getInstance();
$autoloader->setFallbackAutoloader(true);

// load the application configuration
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', 'development'); //'development'); 
//$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/application.xml', 'development');
Zend_Registry :: set('config', $config);

//connect to database
$params = array(
              'host'	=>$config->database->hostname,
              'username'=>$config->database->username,
              'password'=>$config->database->password,
              'dbname'	=>$config->database->database
          );
$db = Zend_Db::factory($config->database->type, $params);
Zend_Registry::set('db', $db);

$captcha_config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', 'captcha');
Zend_Registry::set('captcha_config', $captcha_config);

// create the application logger
$logger = new Zend_Log(new Zend_Log_Writer_Stream($config->paths->debug));
Zend_Registry :: set('logger', $logger);

// handle the user request
require_once ('CustomControllerAction.php');
$controller = Zend_Controller_Front :: getInstance();
$controller->setControllerDirectory(APPLICATION_PATH . '/controllers');

// setup the view renderer
require_once 'Templater.php';
$viewRender = new Zend_Controller_Action_Helper_ViewRenderer();
$viewRender->setView(new Templater());
$viewRender->setViewSuffix('tpl');
Zend_Controller_Action_HelperBroker :: addHelper($viewRender);

$controller->dispatch();
?>
